package com.tianpengtech.front.mobile.common.util;

import java.util.HashMap;

/**
 * Created by ggd on 2017/7/17 0017.
 */
public class R extends HashMap {

    private static final Integer SUCCESS = 1;
    private static final Integer ERROR = 2;


    private static final String CODE = "code";
    private static final String MSG = "msg";
    private static final String DATA = "data";



    public static R ok(String msg) {
        R r = new R();
        r.put(CODE,SUCCESS);
        r.put(MSG,msg);
        return r;
    }
    public static R ok() {
        R r = new R();
        r.put(CODE,SUCCESS);
        r.put(MSG,"成功");
        return r;
    }

    public static R fail(String msg) {
        R r = new R();
        r.put(CODE,ERROR);
        r.put(MSG,msg);
        return r;
    }

    public void p(Object key,Object val){
        if (super.get(DATA)!=null){
            R r1= (R) super.get(DATA);
            r1.put(key,val);
        }else{
            R r1 =  new R();
            r1.put(key,val);
            super.put(DATA,r1);
        }
    }
}
